﻿namespace LogManager.TestUtility
{
    using System;
    using System.IO;

    public class FileUtility
    {
        public static FileInfo CreateFile(string path, DateTime? lastWriteTime = null, long size = 1024)
        {
            size *= 1024;
            using (var fs = new FileStream(path, FileMode.Create))
            {
                fs.Seek(size, SeekOrigin.Begin);
                fs.WriteByte(0);
            }

            if (lastWriteTime.HasValue)
                File.SetLastWriteTime(path, lastWriteTime.Value);

            return new FileInfo(path);
        }

        public static byte[] ReadFully(Stream input)
        {
            using (input)
            using (MemoryStream ms = new MemoryStream())
            {
                input.CopyTo(ms);
                return ms.ToArray();
            }
        }
    }
}
